package sort;

/**
 * @Auther: wangliuyang
 * @Date: 2021/4/23 21:24
 * @Description: shell排序
 */
public class ShellSort {
    public  static void shellSort(int[] nums) {
        for (int gap = nums.length / 2; gap > 0 ; gap = gap / 2) {
            for (int i = gap; i < nums.length; i++) {
                int temp = nums[i],j;
                for (j = i; j >=gap && temp < nums[j-gap]; j -= gap) {
                    nums[j] = nums[j-gap];
                }
                nums[j] = temp;
            }
        }
    }

    public static void main(String[] args) {
        int[] array = new int[]{2,5,6,7,3,7,1};
        shellSort(array);
        for (int i : array) {
            System.out.print(i + " ");
        }
    }
}
